package com.punai.customer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.utils.SecurityUtils;
import com.punai.customer.domain.CusLinkGxfeeCategory;
import com.punai.customer.domain.vo.CusGxLinkGkCategoriesVo;
import com.punai.customer.mapper.CusLinkGxfeeCategoryMapper;
import com.punai.customer.service.ICusLinkGxfeeCategoryService;
import com.punai.gk.domain.vo.SimplifyVo;
import com.punai.gk.mapper.GkUseDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 工序分包费用项 关联 材机分类Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-09
 */
@Service
public class CusLinkGxfeeCategoryServiceImpl extends ServiceImpl<CusLinkGxfeeCategoryMapper, CusLinkGxfeeCategory> implements ICusLinkGxfeeCategoryService
{
    @Autowired
    private CusLinkGxfeeCategoryMapper dmcLinkGxfeeCategoryMapper;
    @Autowired
    private GkUseDataMapper gkUseDataMapper;
    @Autowired
    private CusGxLinkGkServiceImpl cusGxLinkGkService;

    /**
     * 查询工序分包费用项 关联 材机分类
     *
     * @param id 工序分包费用项 关联 材机分类主键
     * @return 工序分包费用项 关联 材机分类
     */
    @Override
    public CusLinkGxfeeCategory selectDmcLinkGxfeeCategoryById(String id)
    {
        return null;
    }

    /**
     * 查询工序分包费用项 关联 材机分类列表
     *
     * @param dmcLinkGxfeeCategory 工序分包费用项 关联 材机分类
     * @return 工序分包费用项 关联 材机分类
     */
    @Override
    public List<CusLinkGxfeeCategory> selectDmcLinkGxfeeCategoryList(CusLinkGxfeeCategory dmcLinkGxfeeCategory)
    {
        return dmcLinkGxfeeCategoryMapper.selectDmcLinkGxfeeCategoryList(dmcLinkGxfeeCategory);
    }

    /**
     * 新增工序分包费用项 关联 材机分类
     *
     * @param dmcLinkGxfeeCategory 工序分包费用项 关联 材机分类
     * @return 结果
     */
    @Override
    public int insertDmcLinkGxfeeCategory(CusLinkGxfeeCategory dmcLinkGxfeeCategory)
    {
            return dmcLinkGxfeeCategoryMapper.insert(dmcLinkGxfeeCategory);
    }

    /**
     * 修改工序分包费用项 关联 材机分类
     *
     * @param dmcLinkGxfeeCategory 工序分包费用项 关联 材机分类
     * @return 结果
     */
    @Override
    public int updateDmcLinkGxfeeCategory(CusLinkGxfeeCategory dmcLinkGxfeeCategory)
    {
        return dmcLinkGxfeeCategoryMapper.updateById(dmcLinkGxfeeCategory);
    }

    /**
     * 批量删除工序分包费用项 关联 材机分类
     *
     * @param ids 需要删除的工序分包费用项 关联 材机分类主键
     * @return 结果
     */
    @Override
    public int deleteDmcLinkGxfeeCategoryByIds(String[] ids)
    {
        return dmcLinkGxfeeCategoryMapper.deleteDmcLinkGxfeeCategoryByIds(ids);
    }

    /**
     * 删除工序分包费用项 关联 材机分类信息
     *
     * @param id 工序分包费用项 关联 材机分类主键
     * @return 结果
     */
    @Override
    public int deleteDmcLinkGxfeeCategoryById(String id)
    {
        return dmcLinkGxfeeCategoryMapper.deleteDmcLinkGxfeeCategoryById(id);
    }

    @Override
    public List<CusGxLinkGkCategoriesVo> getTwoChildrenCategories(String gxId) {
        Long companyId = SecurityUtils.getCompanyId();
        List<CusGxLinkGkCategoriesVo> cusGxLinkGkCategoriesVos = dmcLinkGxfeeCategoryMapper.selectListByGxId(gxId, companyId);

        List<SimplifyVo> simplifyVos = gkUseDataMapper.selectIdNameList(companyId);
        Map<String, String> idNameMap = simplifyVos.stream().collect(Collectors.toMap(SimplifyVo::getId, SimplifyVo::getName));

        cusGxLinkGkCategoriesVos.forEach(e -> e.setLinkGkMap(cusGxLinkGkService.addGkName(e.getGkItem(),idNameMap)));
        return cusGxLinkGkCategoriesVos;
    }
}
